I'm trying to filter an array with function but it's giving me an unexpected result